package com.iob.coin.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;
import java.io.File;

/**
 * @Author: GuoXinyuan
 * @Date: 2021/5/29
 * 数据源配置类
 */

@Configuration
public class DatabaseConfig {

    /**
     * 用户数据源
     * @return
     */
    @Bean(name = "userDataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.userdata")
    public DataSource dataSourceFirst() {
        //这种方式的配置默认只满足spring的配置方式，如果使用其他数据连接（druid）,需要自己独立获取配置
        return DataSourceBuilder.create().build();
    }

    /**
     * 第二个数据源
     * @return
     */
    @Bean(name = "covid19DataSource")
    @ConfigurationProperties(prefix = "spring.datasource.covid19")
    public DataSource dataSourceSecond() {

//        DruidDataSource source=new DruidDataSource();
//        source.setDriverClassName("org.apache.jena.jdbc.tdb.TDBDriver");
//        source.setDriverClassName("org.apache.jena.jdbc.remote.RemoteEndpointDriver");
//        source.setUrl(
//                "jdbc:jena:tdb:location="
//                + DatasetConfig.COVID19_DATASET_PATH
//                + "&must-exist=true"
//        );
//        source.setUrl("jdbc:jena:remote:query=http://localhost:3030/covid19/query");
//        source.setTestWhileIdle(false);
//        return source;

        return DataSourceBuilder.create().build();
    }

}
